<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.4/axios.js"></script>
</head>

<body>
    <button>GET</button>
    <button>POST</button>
    <button>AJAX</button>
</body>
<script>
    const btns = document.querySelectorAll('button');
    // 配置baseURL
    axios.defaults.baseURL = 'http://127.0.0.1:8000';
    btns[0].onclick = function() {
        //GET 请求
        axios.get('/axios-server', {
            //url 参数
            params: {
                id: 100,
                vip: 7
            },
            //请求体信息
            Headers: {
                name: 'jackson',
                age: 29
            }
        }).then(value => {
            console.log(value);
        })
    }
    btns[1].onclick = function() {
        axios.post('/axios-server', {
            username: 'admin',
            password: '123'
        }, {
            // url 参数
            params: {
                id: 200,
                vip: 200
            },
            // 请求体参数
            Headers: {
                height: 100,
                weight: 200
            },
        })
    }
    btns[2].onclick = function() {
        axios({
            //请求方法
            method: 'POST',
            // url
            url: 'axios/server',
            //url 参数
            params: {
                vip: 10,
                level: 30
            },
            //头信息参数
            Headers: {
                a: 100,
                b: 200
            },
            //请求体参数
            data: {
                username: 'jackson',
                password: 'aaa'
            }
        })
    }
</script>

</html>